{% extends 'base.html' %} {% block css%}
<style type="text/css">
    .b1 {
        color: blue;
    }
</style>
{% endblock %} {% block body%}
<div class="row">
    <div class="col-md-6">
        <table class="table table-hover table-condensed form-inline">
            <!-- <tr>
        <td width="30%"  style="line-height: 32px">
          Module Power 3V3
        </td>
        <td>
          <input  name = "cb_gpio_1" onclick="cb_gpio_1_evt('P3V3_OSFP_IN_EN')" class="my_checkbox" id="cb_gpio_1_P3V3_OSFP_IN_EN" type="checkbox">
        </td>
        <td></td>
            </tr> -->
            <tr>
                <td style="font-size:12px" width="25">
                    Fan Rate (0-100)
                </td>
                <td width="25">
                    <input class="form-control" type="text" id="fan" style="width:90px; height:30px" />
                </td>
                <td width="50%">
                    <button class="btn btn-primary" onClick="btn_fan_set()">
                        Set
                    </button>

                    <button class="btn btn-danger" onClick="btn_fan_sm_set()" title="Please confirm that the high temperature protection function of the module to be tested has been correctly turned on.">
                        Silent Mode 
                    </button>

                    <button class="btn btn-success" onClick="btn_fan_fsm_set()">
                        Full Speed Mode
                    </button>

                </td>
            </tr>

         <tr class="{{ for_customer }}">
                <td style="font-size:12px">
                    P3V3
                </td>
                <td>
                    <input class="form-control" type="number" step=0.001  max=3.500 min=3.100 value='' id="p3v3" style="width:90px; height:30px" />
                </td>
                <td>
                    <button class="btn btn-primary" onClick="btn_analog2_evt_set('P3V3_OSFP')">
                        Set
                    </button>
                </td>
            </tr> 

           <tr class="{{ for_customer }}">
                <td style="font-size:12px">TWI Interface</td>
                <td style="background: #FFFFCC">
                    <span style="font-size:12px" id="twi_if">---</span>
                </td>
                <td>
                    <button id="btn_get_twi_if" class="btn btn-success">
                        Get
                    </button>
                </td>
            </tr> 

        <tr class="{{ for_customer }}">
                <td style="font-size:12px">Rate</td>
                <td>
                    <select class="form-control" id="twi_rate" style="width:90px; height:30px">
                        <option value="100">100 K</option>
                        <option value="400">400 K</option>
                        <option value="1000">1000 K</option>
                    </select>
                </td>
                <td>
                    <button id="btn_set_twi_rate" class="btn btn-primary">
                        Set
                    </button>
                </td>
            </tr>

            <tr>
                <td style="font-size:12px">RSTN</td>
                <td style="background: #FFFFCC">
                    <select class="form-control" id="pin_idx_20" style="width:90px; height:30px">
                        <option value="0">0</option>
                        <option value="1">1</option>
                    </select>
                    &nbsp;&nbsp;
                    <span style="font-size:12px" id="txt_pin_idx_20">---</span>
                </td>
                <td>
                    <button class="btn btn-success" onclick="btn_get_pin_state(20)">
                        Get
                    </button>
                    <button class="btn btn-primary" onclick="btn_set_pin_state(20)">
                        Set
                    </button>
                </td>
            </tr>
            <tr>
                <td style="font-size:12px">LPWN</td>
                <td style="background: #FFFFCC">
                    <select class="form-control" id="pin_idx_21" style="width:90px; height:30px">
                        <option value="0">0</option>
                        <option value="1">1</option>
                    </select>
                    &nbsp;&nbsp;
                    <span style="font-size:12px" id="txt_pin_idx_21">---</span>
                </td>
                <td>
                    <button class="btn btn-success" onclick="btn_get_pin_state(21)">
                        Get
                    </button>
                    <button class="btn btn-primary" onclick="btn_set_pin_state(21)">
                        Set
                    </button>
                </td>
            </tr>
            <tr>
                <td style="font-size:12px">INTN</td>
                <td style="background: #FFFFCC">
                    <input class="form-control" style="width:90px; height:30px; background-color:#eee" disabled type="text" id="pin_idx_1" />
                    &nbsp;&nbsp;
                    <span style="font-size:12px" id="txt_pin_idx_1">---</span>
                </td>
                <td>
                    <button class="btn btn-success" onclick="btn_get_pin_state(1)">
                        Get
                    </button>
                </td>
            </tr>
            <tr>
                <td style="font-size:12px">PRSN</td>
                <td style="background: #FFFFCC">
                    <input class="form-control" style="width:90px; height:30px; background-color:#eee" disabled type="text" id="pin_idx_2" />
                    &nbsp;&nbsp;
                    <span style="font-size:12px" id="txt_pin_idx_2">---</span>
                </td>
                <td>
                    <button class="btn btn-success" onclick="btn_get_pin_state(2)">
                        Get
                    </button>
                </td>
            </tr>


            <tr>
                <td style="font-size:12px">Module Power</td>
                <td style="background: #FFFFCC">
                    <select class="form-control" id="module_power" style="width:90px; height:30px">
                        <option value="0">OFF</option>
                        <option value="1">ON</option>
                    </select>
                </td>
                <td>
                    <button class="btn btn-success" onclick="btn_get_module_power()">
                        Get
                    </button>
                    <button class="btn btn-primary" onclick="btn_set_module_power(27)">
                        Set
                    </button>
                </td>
            </tr>


            <tr>
                <td style="font-size:12px">CMIS Revision</td>
                <td style="background: #FFFFCC">
                    <select class="form-control" id="cmis_revision" style="width:90px; height:30px">
                        <option value="40">4.0</option>
                        <option value="41">4.1</option>
                         <option value="50">5.0</option>
                    </select>
                </td>
                <td>
                    <button class="btn btn-success" onclick="btn_get_cmis_revision()">
                        Get
                    </button>
                    <button class="btn btn-primary" onclick="btn_set_cmis_revision()">
                        Set
                    </button>
                </td>
            </tr>

        </table>


         <table class="table table-hover table-condensed form-inline">
            <tr>
                <td style="font-size:12px">Programmable Output Power Supported</td>
                <td width="45%" style="background: #FFFFCC">
                    <span style="font-size:12px" id="txt_pops">---</span>
                </td>
                <td width="20%">
                    <button class="btn btn-success" id="btn_get_pops">
                        Get
                    </button>
                </td>
            </tr>
            <tr>
                <td style="font-size:12px">Min Program Output Power</td>
                <td style="background: #FFFFCC">
                    <span style="font-size:12px" id="txt_min_pop">---</span>
                </td>
                <td>
                    <button class="btn btn-success" id="btn_get_min_pop">
                        Get
                    </button>
                </td>
            </tr>
            <tr>
                <td style="font-size:12px">Max Program Output Power</td>
                <td style="background: #FFFFCC">
                    <span style="font-size:12px" id="txt_max_pop">---</span>
                </td>
                <td>
                    <button class="btn btn-success" id="btn_get_max_pop">
                        Get
                    </button>
                </td>
            </tr>


            <tr>
                <td style="font-size:12px">Program Output Power</td>
                <td style="background: #FFFFCC">
                    <input class="form-control" type="text" id="pop_val" style="width:90px; height:30px" />
                    <span style="font-size:12px" id="txt_pop">---</span>
                </td>
                <td>
                    <button class="btn btn-success" id="btn_get_pop">
                        Get
                    </button>
                    <button class="btn btn-primary" id="btn_set_pop">
                        Set
                    </button>
                </td>
            </tr>
        </table>


<!--         <hr>
        <table class="table table-hover table-condensed">
            <tr>
                <td style="font-size:12px">Register</td>
                <td style="background: #FFFFCC">
                    <input type="text" id="dcv_reg" style="width:90px; height:30px" placeholder="address" />
                    &nbsp;&nbsp;
                    <input type="text" id="dcv_reg_val" style="width:90px; height:30px" placeholder="value" />
                    &nbsp;&nbsp;
                    <span style="font-size:12px" id="txt_dcv_reg">---</span>
                </td>
                <td>
                    <button class="btn btn-success" id="btn_get_dcv_reg">
                        Get
                    </button>
                    <button class="btn btn-primary" id="btn_set_dcv_reg">
                        Set
                    </button>
                </td>
            </tr>
            <tr>
                <td style="font-size:12px">Buck1 Voltage</td>
                <td style="background: #FFFFCC">
                    <input type="text" id="dcv_vol1" style="width:90px; height:30px" />
                    &nbsp;&nbsp;
                    <span style="font-size:12px" id="txt_dcv_vol1">---</span>
                </td>
                <td>
                    <button class="btn btn-success" id="btn_get_dcv_vol1">
                        Get
                    </button>
                    <button class="btn btn-primary" id="btn_set_dcv_vol1">
                        Set
                    </button>
                </td>
            </tr>
            <tr>
                <td style="font-size:12px">Buck2 Voltage</td>
                <td style="background: #FFFFCC">
                    <input type="text" id="dcv_vol2" style="width:90px; height:30px" />
                    &nbsp;&nbsp;
                    <span style="font-size:12px" id="txt_dcv_vol2">---</span>
                </td>
                <td>
                    <button class="btn btn-success" id="btn_get_dcv_vol2">
                        Get
                    </button>
                    <button class="btn btn-primary" id="btn_set_dcv_vol2">
                        Set
                    </button>
                </td>
            </tr>
            <tr>
                <td style="font-size:12px">COSA Power</td>
                <td>
                    <select id="cosa_power" style="width:90px; height:30px">
                        <option value=0>OFF</option>
                        <option value=1>ON</option>
                    </select>
                </td>
                <td>
                    <button class="btn btn-primary" id="btn_set_cosa_power">
                        Set
                    </button>
                </td>
            </tr>
        </table>
        <hr>
        <table class="table table-hover table-condensed">
            <tr>
                <td style="font-size:12px">DDB Password</td>
                <td style="background: #FFFFCC">
                    <span style="font-size:12px" id="txt_ddb_password">---</span>
                </td>
                <td>
                    <button id="btn_set_ddb_password" class="btn btn-primary">
                        Set
                    </button>
                </td>
            </tr>
        </table>
        <br><br> -->
    </div>
    <!-- end of md-8 -->

    <div class="col-md-6">
        <table class="table table-hover table-condensed form-inline">
            <tr>
                <td style="font-size:12px" width="30%">Module State</td>
                <td style="background: #FFFFCC" width="40%">
                    <span style="font-size:12px" id="txt_module_state">---</span>
                </td>
                <td width="25%">
                    <button class="btn btn-success" onclick="btn_get_module_state()">
                        Get
                    </button>
                </td>
            </tr>

            <tr>
                <td style="font-size:12px" width="30%">Data Path State</td>
                <td style="background: #FFFFCC" width="40%">
                    <span style="font-size:12px" id="txt_dp_state">---</span>
                </td>
                <td>
                    <button class="btn btn-success" onclick="btn_get_dp_state()">
                        Get
                    </button>
                </td>
            </tr>
        </table>


        <h4>
        Module Information 
        &nbsp;&nbsp;
        <a class="btn btn-xs btn-default" role="button" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
            <i class="glyphicon glyphicon-sort"></i> Collapse
        </a>
        </h4>
        <div class="collapse" id="collapseExample">
        <table class="table table-hover">
            
            <div id="mod_info_txt">---</div>

            <tr>
                <td></td>
                <td></td>
                <td>
                    <button class="btn btn-success" id="btn_get_mod_info">
                        Get
                    </button>
                </td>
            </tr>
        </table>
        </div>
        <br>

        <h4>Support Multiple Application</h4>
        <table class="table table-hover">
            <tr>
                <td style="font-size: 12px" width="35%">
                    Current Active
                </td>
                <td>
                    <span id="mod_info_txt1" style="color:blue;font-size: 14px">---</span>
                </td>

                <td width="25%">
                    <button class="btn btn-success" id="btn_get_current_active_application">
                    Get
                    </button>
                </td>
            </tr>

            <tr>
                <td style="font-size: 12px" width="35%">
                    Apply Application
                </td>
                <td>
                    <select class="form-control" style="width:100px; height:30px" id="app_mode">
                        <option value="1x400GE">1x400GE</option>
                        <option value="4x100GE">4x100GE</option>
                    </select>
                </td>

                <td>
                    <button class="btn btn-primary" id="btn_set_app_mode">
                    Set
                    </button>

                    <button class="btn btn-danger" id="btn_save_app_mode">
                    <i class="glyphicon glyphicon-save"></i> Save
                    </button>
                </td>
            </tr>

        </table>


    </div>

</div>
{% endblock %} {% block js%}
{{ super() }}
<script type="text/javascript">


function btn_fan_set() {
    fan = $("#fan").val();
    if (fan == "" || fan < 0 || fan > 100) {
        alert("Invalid value.");
        return false;
    }

    $.post(
        "api/btn_fan_set", 
        {
            fan: fan
        },
        function(data, status) {
            toastr["success"]("Command successfully issued.");
            console.log("data: " + data);
        }
    );
}

function btn_fan_fsm_set() {
    $.post(
        "api/btn_fan_set", 
        {
            fan: 100
        },
        function(data, status) {
            toastr["success"]("Set full speed mode.");
            console.log("data: " + data);
        }
    );
}

function btn_fan_sm_set() {
    $.post(
        "api/btn_fan_set", 
        {
            fan: 30
        },
        function(data, status) {
            toastr["warning"]("Set silent mode.");
            console.log("data: " + data);
        }
    );
}


function btn_get_twi_rate() {
    url = "/api/get_twi_rate";
    $.get(url, function(data, status) {
        console.log(data);
        $("#twi_rate")
            .val(data)
            .prop("selected", true);
    });
}

function btn_get_twi_if() {
    url = "/api/get_twi_if";
    $.get(url, function(data, status) {
        console.log(data);
        if (data == 1) $("#twi_if").html("MCU");
        else $("#twi_if").html("FPGA");
    });
}

function btn_get_module_state() {
    url = "/api/get_module_state";
    $.get(url, function(data, status) {
        console.log(data);
        $("#txt_module_state").html(data);
    });
}

function btn_get_dp_state() {
    url = "/api/get_dp_state";
    $.get(url, function(data, status) {
        console.log(data);
        $("#txt_dp_state").html(data);
    });
}


function btn_analog2_evt_get(item) {
    $.post(
        "api/analog2_evt_get", {
            item: item
        },
        function(data, status) {
            console.log("data: " + data);
            cells = data.split(",");
            $("#p3v3").val(cells[0]);
        }
    );
}

function btn_analog2_evt_set(item) {
    analog2_phy_val = $("#p3v3").val();
    if (analog2_phy_val == "" || analog2_phy_val < 3.1 || analog2_phy_val > 3.5) {
        alert("Invalid value.");
        return false;
    }

    $.post(
        "api/analog2_evt_set", {
            //item:'P3V3_OSFP',
            analog2_phy_val: analog2_phy_val
        },
        function(data, status) {
            console.log("data: " + data);
            toastr["success"]("Command successfully issued.");
            btn_analog2_evt_get("P3V3_OSFP");
        }
    );
}

function btn_get_pin_state(idx) {
    var txt;
    $.post(
        "api/get_pin_state", {
            idx: idx
        },
        function(data, status) {
            console.log("data: " + data);
            if (idx == 20) {
                txt = data == 0 ? "Reset" : "No Reset";
            } else if (idx == 21) {
                txt = data == 0 ? "High Power Up" : "Low Power";
            } else if (idx == 1) {
                txt = data == 0 ? "INTN Low" : "INTN High";
            } else if (idx == 2) {
                txt = data == 0 ? "Module Present" : "No Module";
            } else txt = "---";

            $("#txt_pin_idx_" + idx).html(txt);
            $("#pin_idx_" + idx)
                .val(data)
                .prop("selected", true);
            $("#pin_idx_" + idx).val(data);
        }
    );
}

function btn_set_pin_state(idx) {
    var pin_idx_val = $("#pin_idx_" + idx).val();
    $.post(
        "api/set_pin_state", {
            idx: idx,
            pin_idx_val: pin_idx_val
        },
        function(data, status) {
            toastr["success"]("Command successfully issued.");
            console.log("data: " + data);
        }
    );
}


function btn_get_module_power() {
    var txt;
    $.post(
        "api/get_module_power", {
        },
        function(data, status) {
            console.log("data: " + data);
            $("#module_power").val(data).prop("selected", true);
        }
    );
}

function btn_set_module_power(idx) {
    var val = $("#module_power").val();

    $.post(
        "api/set_module_power", {
            idx: 27,
            val: val
        },
        function(data, status) {
            toastr["success"]("Command successfully issued.");
            console.log("data: " + data);
        }
    );
}




function btn_get_cmis_revision() {
    var txt;
    $.post(
        "api/get_cmis_revision", {
        },
        function(data, status) {
            console.log("data: " + data);
            $("#cmis_revision").val(data).prop("selected", true);
        }
    );
}

function btn_set_cmis_revision() {
    var cmis_revision = $("#cmis_revision").val();
    $.post(
        "api/set_cmis_revision", {
            cmis_revision : cmis_revision
        },
        function(data, status) {
            toastr["success"]("Command successfully issued.");
            console.log("data: " + data);
        }
    );
}


function get_msa_values() {
    url = "/api/get_msa_values";
    $.get(url, function(data, status) {
        console.log(data);
        d = JSON.parse(data);

        $("#twi_rate").val(d["twi_rate"]).prop("selected", true);
        $("#twi_if").html(d["twi_if"] == 0 ? "FPGA" : "MCU");

        cells = d["p3v3"].split(",");
        $("#p3v3").val(cells[0]);

        $("#txt_pin_idx_20").html( d["txt_pin_idx_20"] == 0 ? "Reset" : "No Reset");
        $("#txt_pin_idx_21").html(d["txt_pin_idx_21"] == 0 ? "High Power Up" : "Low Power");
        $("#txt_pin_idx_1").html(d["txt_pin_idx_1"] == 0 ? "INTN Low" : "INTN High");
        $("#txt_pin_idx_2").html(d["txt_pin_idx_2"] == 0 ? "Module Present" : "No Module");

        $("#pin_idx_20").val(d["txt_pin_idx_20"]).prop("selected", true);
        $("#pin_idx_21").val(d["txt_pin_idx_21"]).prop("selected", true);

        $("#pin_idx_1").val(d["txt_pin_idx_1"]);
        $("#pin_idx_2").val(d["txt_pin_idx_2"]);
    });
}


$(document).ready(function() {
    toastr.options = {
        "closeButton": true,
        "timeOut": "1000",
        "positionClass": "toast-top-center"
    }

    // btn_get_twi_rate();
    // btn_get_twi_if();
    // btn_analog2_evt_get("P3V3_OSFP");
    // btn_get_pin_state(20);
    // btn_get_pin_state(21);
    // btn_get_pin_state(1);
    // btn_get_pin_state(2);
    get_msa_values();
    btn_get_module_power();
    btn_get_cmis_revision();

    $("#btn_set_ddb_password").click(function() {
      $.post(
          "api/btn_set_ddb_password", {},
          function(data, status) {
              console.log("data: " + data);
              toastr["success"]("Command successfully issued.");
              $("#txt_ddb_password").html(data);
          }
      );
    })


    $("#btn_set_twi_rate").click(function() {
        var twi_rate = $("#twi_rate").val();
        $.post(
            "api/set_twi_rate", {
                twi_rate: twi_rate
            },
            function(data, status) {
                toastr["success"]("Command successfully issued.");
                console.log("data: " + data);
            }
        );
    });

    $("#btn_get_twi_if").click(function() {
        btn_get_twi_if();
    });

    $("#btn_get_dcv_reg").click(function() {
        $.post(
            "api/get_dcv_reg", {
                dcv_reg: $("#dcv_reg").val()
            },
            function(data, status) {
                toastr["success"]("Command successfully issued.");
                console.log("data: " + data);
                $("#txt_dcv_reg").html(data);
            }
        );
    });

    $("#btn_set_dcv_reg").click(function() {
        var dcv_reg = $("#dcv_reg").val();
        var dcv_reg_val = $("#dcv_reg_val").val();
        $.post(
            "api/set_dcv_reg", {
                dcv_reg: dcv_reg,
                dcv_reg_val: dcv_reg_val
            },
            function(data, status) {
                toastr["success"]("Command successfully issued.");
                console.log("data: " + data);
            }
        );
    });


    $("#btn_get_dcv_vol1").click(function() {
        $.post(
            "api/get_dcv_vol1", {
                // idx: $("#dcv_vol1").val()
            },
            function(data, status) {
                toastr["success"]("Command successfully issued.");
                console.log("data: " + data);
                $("#txt_dcv_vol1").html(data);
            }
        );
    });

    $("#btn_set_dcv_vol1").click(function() {
        var dcv_vol1 = $("#dcv_vol1").val();
        $.post(
            "api/set_dcv_vol1", {
                dcv_vol1: dcv_vol1
            },
            function(data, status) {
                toastr["success"]("Command successfully issued.");
                console.log("data: " + data);
            }
        );
    });


    $("#btn_get_dcv_vol2").click(function() {
        $.post(
            "api/get_dcv_vol2", {
                // idx: $("#dcv_vol2").val()
            },
            function(data, status) {
                toastr["success"]("Command successfully issued.");
                console.log("data: " + data);
                $("#txt_dcv_vol2").html(data);
            }
        );
    });

    $("#btn_set_dcv_vol2").click(function() {
        var dcv_vol2 = $("#dcv_vol2").val();
        $.post(
            "api/set_dcv_vol2", {
                dcv_vol2: dcv_vol2
            },
            function(data, status) {
                toastr["success"]("Command successfully issued.");
                console.log("data: " + data);
            }
        );
    });

    $("#btn_set_cosa_power").click(function() {
        var cosa_power = $("#cosa_power").val();
        $.post(
            "api/cosa_power", {
                cosa_power: cosa_power
            },
            function(data, status) {
                toastr["success"]("Command successfully issued.");
                console.log("data: " + data);
            }
        );
    });

    $("#btn_get_pops").click(function() {
        $.post(
            "api/get_pops", {
            },
            function(data, status) {
                // toastr["success"]("Command successfully issued.");
                console.log("data: " + data);
                $("#txt_pops").html(data);
            }
        );
    });

    $("#btn_get_min_pop").click(function() {
        $.post(
            "api/get_min_pop", {
            },
            function(data, status) {
                // toastr["success"]("Command successfully issued.");
                console.log("data: " + data);
                $("#txt_min_pop").html(data);
            }
        );
    });


    $("#btn_get_max_pop").click(function() {
        $.post(
            "api/get_max_pop", {
            },
            function(data, status) {
                // toastr["success"]("Command successfully issued.");
                console.log("data: " + data);
                $("#txt_max_pop").html(data);
            }
        );
    });

    $("#btn_get_pop").click(function() {
        $.post(
            "api/get_pop", {
            },
            function(data, status) {
                // toastr["success"]("Command successfully issued.");
                console.log("data: " + data);
                $("#txt_pop").html(data);
            }
        );
    });

    $("#btn_set_pop").click(function() {
        $.post(
            "api/set_pop", {
                pop_val : $("#pop_val").val()
            },
            function(data, status) {
                toastr["success"]("Command successfully issued.");
                console.log("data: " + data);
                // $("#txt_pop").html(data);
            }
        );
    });


   $('#btn_get_mod_info').click(function() {
        url = "/api/btn_get_mod_info";
        $.get(url, function(data, status) {
            console.log(data)
            // $("#fileinfo").html("commit ok!");
            $("#mod_info_txt").html(data);
        });
    })

    $('#btn_get_current_active_application').click(function() {
        url = "/api/btn_get_current_active_application";
        $.get(url, function(data, status) {
            console.log(data)
            // $("#fileinfo").html("commit ok!");
            $("#mod_info_txt1").html(data);
        });
    })


    $("#btn_set_app_mode").click(function() {
        // toastr["success"]("Restart takes effect.");
        $.post(
            "api/set_app_mode", {
                app_mode: $("#app_mode").val()
            },
            function(data, status) {
                console.log("data: " + data);
                toastr["success"]("It will take effect after re-power up module.");
            }
        );
    });

    $("#btn_save_app_mode").click(function() {
        $.post(
            "api/save_app_mode", {
            },
            function(data, status) {
                console.log("data: " + data);
                toastr["success"]("Command successfully issued.");
            }
        );
    });


});
</script>
{% endblock %}